using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Domain.Entities;

namespace JGSY.CMS.LowCode.Platform.Domain.Interfaces
{
    /// <summary>
    /// 字段仓储接口
    /// </summary>
    public interface IFieldRepository : IRepository<Field>
    {
        /// <summary>
        /// 根据表单ID获取字段列表
        /// </summary>
        /// <param name="formId">表单ID</param>
        /// <returns>字段列表</returns>
        Task<List<Field>> GetByFormIdAsync(long formId);

        /// <summary>
        /// 根据字段名称查找字段
        /// </summary>
        /// <param name="formId">表单ID</param>
        /// <param name="fieldName">字段名称</param>
        /// <returns>字段实体</returns>
        Task<Field?> GetByNameAsync(long formId, string fieldName);

        /// <summary>
        /// 根据字段类型获取字段列表
        /// </summary>
        /// <param name="fieldType">字段类型</param>
        /// <returns>字段列表</returns>
        Task<List<Field>> GetByTypeAsync(string fieldType);

        /// <summary>
        /// 获取必填字段列表
        /// </summary>
        /// <param name="formId">表单ID</param>
        /// <returns>必填字段列表</returns>
        Task<List<Field>> GetRequiredFieldsAsync(long formId);

        /// <summary>
        /// 检查字段名称是否存在
        /// </summary>
        /// <param name="formId">表单ID</param>
        /// <param name="fieldName">字段名称</param>
        /// <param name="excludeId">排除的ID</param>
        /// <returns>是否存在</returns>
        Task<bool> IsNameExistsAsync(long formId, string fieldName, long? excludeId = null);

        /// <summary>
        /// 批量更新字段排序
        /// </summary>
        /// <param name="fieldOrders">字段ID和排序值的字典</param>
        /// <returns>是否成功</returns>
        Task<bool> BatchUpdateSortOrderAsync(Dictionary<long, int> fieldOrders);
    }
}
